package com.sgb.goods.utils.base.adapter;

import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.entity.MultiItemEntity;

import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * RecycleView多布局
 * @param <T>
 * @author cyj
 */
@Deprecated
public class BaseCommonMultiAdapter<T extends MultiItemEntity> extends BaseMultiItemQuickAdapter<T, BaseViewHolder> {

    /** BR variableId */
    private int variableId;

    public BaseCommonMultiAdapter(List<T> list) {
        super(list);
    }

    public BaseCommonMultiAdapter(List<T> list, int variableId) {
        super(list);
        this.variableId = variableId;
    }

    protected void convert(BaseViewHolder baseHolder, ViewDataBinding dataBinding, T entity) {}

    @Override
    final protected void convert(@NotNull BaseViewHolder baseHolder, T entity) {
        ViewDataBinding dataBinding = DataBindingUtil.bind(baseHolder.itemView);
        if(null != dataBinding) {
            if(this.variableId > 0) {
                dataBinding.setVariable(this.variableId, entity);
            }
            //防止数据闪烁
            dataBinding.executePendingBindings();
        }
        convert(baseHolder, dataBinding, entity);
    }
}
